package web.Node;

import domain.Node;
import domain.Project;
import service.User_Service;
import service.impl.User_ServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/receiveNodeServlet")
public class ReceiveNodeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置页面编码
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");
        //获取传入的项目ID
        String node_id = request.getParameter("node_id");
        System.out.println(node_id);
        //调用service查询
        User_Service user_service = new User_ServiceImpl();
        //查询这个节点的信息
        Node node = user_service.findOneNode(node_id);
        request.setAttribute("node",node);
        /*查询所有项目*/
        List<Project> projects = user_service.findProject();
        request.setAttribute("project",projects);

        request.getRequestDispatcher("/node/upNode.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
